package mysql

import (
	"gorm.io/gorm"
	"time"
)

type Trip struct {
	gorm.Model
	UserId     int64     `gorm:"int" json:"userId"`
	DriverId   int64     `gorm:"int" json:"driverId"`
	StarAddr   string    `gorm:"varchar(255)" json:"starAddr"`
	EndAddr    string    `gorm:"varchar(255)" json:"endAddr"`
	FinishedAt time.Time `gorm:"varchar(255)" json:"finishedAt"`
	Status     string    `gorm:"varchar(20)" json:"status"`
}

func (t *Trip) FindByUserId(userId int64) (trip []*Trip, err error) {
	err = DB.Where("user_id = ?", userId).Find(&trip).Error
	if err != nil {
		return nil, err
	}
	return trip, nil
}
